<template>
  <view class="goods-card" :class="classes" @tap="navToGoodsDetail(goods)">
    <view class="goods-card-cover">
      <a-img-loader :src="goods.thumbnail" />
    </view>
    <view class="goods-card-info">
      <text class="goods-name">{{ goods.name }}</text>
      <text v-if="type=='row'" class="goods-keys">{{ goods.description }}</text>
      <view style="flex:1;"></view>
      <view class="goods-card-info__btm">
        <template v-if="type=='col'">
          <image class="goods-like-img" :src="likeImage" @tap.stop="togLike" />
          <text class="goods-amount">￥{{ amountRetail(goods) }}起</text>
        </template>
        <template v-else>
          <text class="goods-amount">￥{{ amountRetail(goods) }}起</text>
          <view class="goods-like">
            <text v-if="totalLike" class="goods-like-count">{{ totalCount||'--' }}人喜欢</text>
            <image class="goods-like-img" :src="likeImage" @tap.stop="togLike" />
          </view>
        </template>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  components: {},
  props: {
    type: {
      type: String,
      default: 'col'
    },
    goods: {
      type: Object
    },
    totalCount: Number,
    totalLike: Boolean
  },
  computed: {
    classes () {
      let res = ''
      if (this.type) {
        res += ` goods-card--${this.type}`
      }
      if (this.totalLike) {
        res += ' goods-card--total-like'
      }
      return res
    },
    likeImage () {
      return this.$options.filters.prefixOssUrl(`icon/${'not'}like.png`)
    }
  },
  methods: {
    togLike () {
      this.toast('收藏功能尚在开发中，敬请期待！')
    }
  }
}
</script>

<style lang="less">
.goods-card {
  background: #fff;
  border-radius: 10rpx;
  overflow: hidden;

  &--col {
    .goods-card-cover {
      margin: 10rpx;
      width: 304rpx;
      height: 320rpx;
    }

    .goods-card-info {
      font-size: 0;
      padding: 18rpx;

      &__btm {
        padding-top: 25rpx;
        .flexLayout(@j: space-between, @a: center);
      }
    }
  }

  &--row {
    .flexLayout();
    padding: 10rpx;

    .goods-card-cover {
      width: 280rpx;
      height: 280rpx;
    }

    .goods-card-info {
      .flexLayout(@dir: column);
      flex: 1;
      padding: 20rpx 23rpx;

      &__btm {
        padding-top: 25rpx;
        .flexLayout(@j: space-between, @a: center);
      }
    }

    &.goods-card--total-like {
      .goods-card-info {
        padding: 0 11rpx 0 20rpx;

        &__btm {
          padding-top: 10rpx;
          flex-wrap: wrap;
        }
      }

      .goods-amount {
        width: 100%;
      }

      .goods-like {
        .flexLayout(@a: center);
        width: 100%;
      }
    }
  }

  .goods-name {
    .textOverflow(2);
    height: 77rpx;
    font-size: 30rpx;
    font-weight: 500;
    color: #333;
    line-height: 40rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
  }

  .goods-keys {
    width: 310rpx;
    margin-top: 20rpx;
    font-size: 26rpx;
    font-weight: 500;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .goods-like {
    &-count {
      margin-right: 31rpx;
      flex: 1;
      text-align: right;
      font-size: 26rpx;
      font-weight: 500;
      color: #999;
    }

    &-img {
      width: 36rpx;
      height: 36rpx;
    }
  }

  .goods-amount {
    font-size: 36rpx;
    font-weight: bold;
    color: #ff0000;
  }
}
</style>